package com.itcat.api;/*
 * @Author: gonhsl
 * @Date:2022-04-02-17:33
 * */

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itcat.api.mysql.SmsFlashPromotionApi;
import com.itcat.mapper.SmsFlashPromotionMapper;
import com.itcat.mysql.pojo.SmsFlashPromotion;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

@DubboService
public class SmsFlashPromotionApiImpl implements SmsFlashPromotionApi {
  @Autowired
  private SmsFlashPromotionMapper smsFlashPromotionMapper;
    @Override
    public Page<SmsFlashPromotion> findList(Integer pageNum, Integer pageSize, String keyword) {
        Page<SmsFlashPromotion> promotionPage = new Page<>(pageNum, pageSize);
        LambdaQueryWrapper<SmsFlashPromotion> wrapper = new LambdaQueryWrapper<>();
        wrapper.like(keyword!=null,SmsFlashPromotion::getTitle,keyword);
        Page<SmsFlashPromotion> page = smsFlashPromotionMapper.selectPage(promotionPage, wrapper);
        return page;

//         smsFlashPromotionMapper.
    }

    @Override
    public void create(SmsFlashPromotion smsFlashPromotion) {
        smsFlashPromotionMapper.insert(smsFlashPromotion);
    }

    @Override
    public void delete(Integer id) {
        smsFlashPromotionMapper.deleteById(id);
    }

    @Override
    public void updateStatus(Integer id, Integer status) {
        LambdaUpdateWrapper<SmsFlashPromotion> updateWrapper = new LambdaUpdateWrapper<>();
        updateWrapper.eq(SmsFlashPromotion::getId,id).set(SmsFlashPromotion::getStatus,status);
        SmsFlashPromotion smsFlashPromotion = new SmsFlashPromotion();
        smsFlashPromotion.setStatus(status);
        smsFlashPromotionMapper.update(smsFlashPromotion,updateWrapper);
    }

    @Override
    public void update(SmsFlashPromotion smsFlashPromotion, Integer id) {
//        LambdaUpdateWrapper<SmsFlashPromotion> updateWrapper = new LambdaUpdateWrapper<>();
//        updateWrapper.eq(SmsFlashPromotion::getId,id).setEntity(smsFlashPromotion);
//        smsFlashPromotionMapper.update(smsFlashPromotion,updateWrapper);
        smsFlashPromotionMapper.updateById(smsFlashPromotion);
    }
}
